package com.bean.vo;

import java.io.Serializable;
import java.util.List;

/**
 * 分页助手
 */
public class PageAssistant<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    /** 总记录数 */
    private int count;
    /** 总页数 */
    private int totalPage;
    /** 页面大小 */
    private int pageSize = 5;
    /** 当前页 */
    private int currPage = 1;
    /** 起始记录序号 */
    private int startCode;
    /** 页面内容 */
    private List<T> items;

    @Override
    public String toString() {
        return "PageAssistant{" +
                "count=" + count +
                ", totalPage=" + totalPage +
                ", pageSize=" + pageSize +
                ", currPage=" + currPage +
                ", startCode=" + startCode +
                ", items=" + items +
                '}';
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
        setTotalPage();
    }

    public int getTotalPage() {
        return totalPage;
    }

    private void setTotalPage() {

        this.totalPage = count / pageSize;

        if (count % pageSize != 0){
            totalPage++;
        }
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
        setTotalPage();
        setStartCode();
    }

    public int getCurrPage() {
        return currPage;
    }

    public void setCurrPage(int currPage) {
        this.currPage = currPage;
        setStartCode();
    }

    public int getStartCode() {
        return startCode;
    }

    private void setStartCode() {
        this.startCode = (currPage - 1) * pageSize;
}

    public List<T> getItems() {
        return items;
    }

    public void setItems(List<T> items) {
        this.items = items;
    }
}
